﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Dashboard.Models;
using Dashboard.Includes;
using System.Web.Routing;
using Dashboard.Languages.RU;

namespace Dashboard.Controllers
{
    public class StatController : Controller
    {
        IStatDataProvider dataProvider;

        public StatController()
            : this(new StatDataProvider())
        { }

        public StatController(IStatDataProvider dataProvider)
        {
            this.dataProvider = dataProvider;
        }

        public ActionResult Display(string type, string displayType)
        {
            List<byte> model = dataProvider.GetModel(type, displayType);
            String displayView = dataProvider.GetDisplayView(displayType);
            String menu = dataProvider.GetMenu(type);

            if ((model == null) || (displayView == null)) return new HttpNotFoundResult();

            ViewBag.type = type;
            ViewBag.menu = menu;
            ViewBag.Title = string.Format("{0} - RPM", type);
            return View(displayView, null, model);
        }

        public ActionResult MixedDisplay(string displayType)
        {
            List<List<byte>> mixedModel;
            MixedPlotConstants plotConstants;

            string menu = dataProvider.GetMenu();
            plotConstants = dataProvider.GetPlotConstants(displayType);
            mixedModel = dataProvider.GetModel(displayType);
            if ((mixedModel == null) || (plotConstants.PointsCount == 0)) return new HttpNotFoundResult();

            ViewBag.menu = menu;
            ViewBag.constants = plotConstants;
            ViewBag.namesCounter = DataManager.Instance.GetNamesAllCounter();
            ViewBag.Title = "Common - RPM";
            return View("Mixed", null, mixedModel);
        }

        public ActionResult AjaxDisplay(string type, string displayType)
        {
            List<byte> model;

            model = dataProvider.GetModel(type, displayType);
            if (model == null) return new HttpNotFoundResult();

            return View("Ajax", null, model);
        }

        public ActionResult FreeSpace()
        {
            ViewBag.Disks = Dashboard.Models.DiskSpace.GetTotalHDDSize();

            ViewBag.Coma = ',';
            ViewBag.Title = "Disk Space - RPM";
            return View();
        }

        public ActionResult Home()
        {
            ViewBag.Title = "RPM";
            return View();
        }
    }
}
